<?php
/** 
**********************************************************
* CYLON PARAMETER file                                   *
* ------------------------------------------------------ *
*  cylon.zip   - in root or update folder /              *
*                cylon installation files                *
*  install.zip - in root or update folder /              *
*                delete all file exept cylon             * 
*                and install files                       *
*  *.zip       - update folder                           *
*                update files from zip file              *
*  *.sql       - update folder                           *
*                update database from sql file           *
*                                                        *
* ZIP files                                              *
*  /files      - remove "files/" from source path        *
*  /database   - dont install file,                      *
*                only use .sql in this folder            *
*  any file    - copy file with full path into root      * 
*                                                        *
**********************************************************
*/ 
  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i: s") . " GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");
  header('Content-type: application/xml; charset=utf-8');

  include_once('config.php');
  
  switch (@$_REQUEST['token']){
    case SECRET: /** Normal mode *****************************************************************************/
         include_once(ROOT.INCLUDES ."class_mysql.php");
         include_once(ROOT.INCLUDES ."class_template.php");
         include_once(ROOT.INCLUDES ."class_files.php");
          
         set_time_limit(300);
          
         $XML = new xmlWriter();
          
         $XML->openURI('php://output'); 
         
         $XML->startDocument('1.0','UTF-8');
         $XML->setIndent(4); 
          
         $XML->startElement('Cylon_update_and_install_robot'); 
         $XML->writeAttribute('version', '3.0'); 
         $XML->writeAttribute('sourcelink', $_SERVER['HTTP_HOST'] ); 
        
        /** update files *****************************************************************************/
            
         checkDirectory(ROOT,INCLUDES);
         checkDirectory(ROOT,REPORT);
         checkDirectory(ROOT,TEMPLATE);
         checkDirectory(ROOT,BACKUP);
         checkDirectory(ROOT,UPDATE);
         checkDirectory(ROOT,MEDIA);
         checkDirectory(ROOT,ARCHIVE);
               
         $DB = new mysql(SQL_HOST,SQL_USERNAME,SQL_PASSWORD,SQL_DBINSTALL);
               
         updatezipfile(ROOT.'cylon.zip'         ,ROOT );             /* cylont helyreteszi */
         updatezipfile(ROOT.UPDATE.'cylon.zip'  ,ROOT );             /* cylont helyreteszi */
         updatezipfile(ROOT.'install.zip'       ,DESTINATION );      /* instal anyag */
         updatezipfile(ROOT.UPDATE.'install.zip',DESTINATION );      /* instal anyag */
          
         foreach(getListFiles (ROOT.UPDATE,'.zip') as $updatefile){  /* update zip files */
           updatezipfile($updatefile, DESTINATION);};
          
         foreach(getListFiles (ROOT.UPDATE,'.sql') as $updatefile){  /* update sql files */
           updateSQLfile($updatefile);};
        
         $XML->endElement (); 
         $XML->endDocument ();
         $XML->flush();
          
         @$DB->close();
         break;
         
         
         
    case token('upload'): /** Upload file *****************************************************************************/
 
         $SafeFile = @$_FILES['uploaded']['name']; 
         $SafeFile = str_replace("#", "No.",    $SafeFile); 
         $SafeFile = str_replace("$", "Dollar", $SafeFile); 
         $SafeFile = str_replace("%", "Percent",$SafeFile); 
         $SafeFile = str_replace("^", "",       $SafeFile); 
         $SafeFile = str_replace("&", "and",    $SafeFile); 
         $SafeFile = str_replace("*", "",       $SafeFile); 
         $SafeFile = str_replace("?", "",       $SafeFile); 
         $XML = new xmlWriter();
         $XML->openURI('php://output'); 
         $XML->startDocument('1.0','UTF-8');
         $XML->setIndent(4);
         
         if(@copy(@$_FILES['uploaded']['tmp_name'], ROOT.UPDATE.$SafeFile)){ //IF IT HAS BEEN COPIED... 
           $XML->startElement('cylon_upload_robot'); 
             $XML->writeAttribute('version', VERSION); 
             $XML->writeAttribute('sourcelink', @$_SERVER['HTTP_HOST'] ); 
             $XML->startElement ('upload_file');
               $XML->writeAttribute('process', 'successful');         
               $XML->writeElement ('file_name', @$_FILES['uploaded']['name']);
               $XML->writeElement ('file_size', round(@$_FILES['uploaded']['size']/1000)."KB");
               $XML->writeElement ('max_size', ini_get('post_max_size'));
               $XML->writeElement ('upload_directory', ROOT.UPDATE);
             $XML->endElement ();
           $XML->endElement (); 
         } else { 
           $XML->startElement('cylon_upload_robot'); 
             $XML->writeAttribute('version', VERSION); 
             $XML->writeAttribute('sourcelink', @$_SERVER['HTTP_HOST'] ); 
             $XML->startElement ('upload_file');
               $XML->writeAttribute('process', 'fail');         
               $XML->writeElement ('file_name', @$_FILES['uploaded']['name']);
               $XML->writeElement ('file_size', round(@$_FILES['uploaded']['size']/1000)."KB");
               $XML->writeElement ('max_size', ini_get('post_max_size'));
               $XML->writeElement ('upload_directory', ROOT.UPDATE);
             $XML->endElement ();
           $XML->endElement (); 
         } 
         $XML->endDocument ();
         $XML->flush();
         break;
                
    default:
        echo "SZAR";
        die;
  };
  
 
          
?>